﻿<Window x:Class="ChessPlatform.UI.Desktop.NewGameWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:ChessPlatform.UI.Desktop.Controls"
        xmlns:commands="clr-namespace:ChessPlatform.UI.Desktop.Commands"
        xmlns:viewModels="clr-namespace:ChessPlatform.UI.Desktop.ViewModels"
        Title="New Game" Width="700" ShowInTaskbar="False" ResizeMode="NoResize"
        WindowStartupLocation="CenterOwner" SizeToContent="Height" Loaded="Window_Loaded" x:ClassModifier="internal">

    <Window.DataContext>
        <viewModels:NewGameWindowViewModel x:Name="ViewModel" />
    </Window.DataContext>

    <Window.CommandBindings>
        <CommandBinding Command="commands:NewGameWindowCommands.Start" CanExecute="Start_CanExecute"
                Executed="Start_Executed" />
        <CommandBinding Command="Close" Executed="Close_Executed" />
    </Window.CommandBindings>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <GroupBox Grid.Row="0" Grid.Column="0" Header="_White Player" Margin="5">
            <controls:PlayerChoiceControl DataContext="{Binding Path=WhitePlayerViewModel}" />
        </GroupBox>

        <GroupBox Grid.Row="0" Grid.Column="1" Header="_Black Player" Margin="5">
            <controls:PlayerChoiceControl DataContext="{Binding Path=BlackPlayerViewModel}" />
        </GroupBox>

        <GroupBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Header="Start Position (_FEN)" Margin="5">
            <Grid HorizontalAlignment="Stretch" Margin="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <TextBox Grid.Column="0" HorizontalAlignment="Stretch" Margin="5"
                        AcceptsReturn="False" AcceptsTab="False" TextWrapping="NoWrap" MaxLines="1"
                        Text="{Binding Fen,UpdateSourceTrigger=PropertyChanged}">
                    <TextBox.Style>
                        <Style TargetType="TextBox">
                            <Setter Property="Background" Value="{x:Static SystemColors.WindowBrush}" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsFenValid}" Value="False">
                                    <Setter Property="Background" Value="{x:Static Brushes.Tomato}" />
                                </DataTrigger>
                                <MultiDataTrigger>
                                    <MultiDataTrigger.Conditions>
                                        <Condition Binding="{Binding IsFenValid}" Value="True" />
                                        <Condition Binding="{Binding IsFenDefault}" Value="False" />
                                    </MultiDataTrigger.Conditions>
                                    <Setter Property="Background" Value="{x:Static Brushes.Gold}" />
                                </MultiDataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBox.Style>
                </TextBox>
                <Button Grid.Column="1" HorizontalAlignment="Right" Content="Set _Default" Margin="5" MinWidth="60"
                        Click="SetDefaultFenButton_Click" />
                <Button Grid.Column="2" HorizontalAlignment="Right" Content="_Paste From Clipboard" Margin="5"
                        MinWidth="60"
                        Click="PasteFenFromClipboardButton_Click" />
            </Grid>
        </GroupBox>

        <StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal"
                HorizontalAlignment="Right" Margin="5">
            <Button Content="Start" MinWidth="80" Margin="10,5,10,5" Command="commands:NewGameWindowCommands.Start"
                    IsDefault="True" />
            <Button Content="Cancel" MinWidth="80" Margin="10,5,10,5" Command="Close" IsCancel="True" />
        </StackPanel>
    </Grid>
</Window>